/*****************************************************************
 * Author:  redypon Copyright Knights Warrior
*****************************************************************/
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
using System.IO;

namespace RPCenter.UpdaterUtil
{
    public class Config
    {
        #region The private fields
        private bool enabled = true;
        private string serverUrl = string.Empty;
        private string mainProgressType = string.Empty;
        private string mainProgressName = string.Empty;
        private string mainProgressExe = string.Empty;
        private string mainProgressPath = string.Empty;
        private UpdateFileList updateFileList = new UpdateFileList();
        #endregion

        #region The public property
        public bool Enabled
        {
            get { return enabled; }
            set { enabled = value; }
        }
        public string ServerUrl
        {
            get { return serverUrl; }
            set { serverUrl = value; }
        }
        /// <summary>
        /// exe service
        /// </summary>
        public string MainProgressType
        {
            get { return mainProgressType; }
            set { mainProgressType = value; }
        }
        public string MainProgressName
        {
            get { return mainProgressName; }
            set { mainProgressName = value; }
        }
        public string MainProgressExe
        {
            get { return mainProgressExe; }
            set { mainProgressExe = value; }
        }
        public string MainProgressPath
        {
            get { return mainProgressPath; }
            set { mainProgressPath = value; }
        }
        public UpdateFileList UpdateFileList
        {
            get { return updateFileList; }
            set { updateFileList = value; }
        }
        #endregion

        #region The public method
        public static Config LoadConfig(string file)
        {
            XmlSerializer xs = new XmlSerializer(typeof(Config));
            StreamReader sr = new StreamReader(file);
            Config config = xs.Deserialize(sr) as Config;
            sr.Close();

            return config;
        }

        public void SaveConfig(string file)
        {
            XmlSerializer xs = new XmlSerializer(typeof(Config));
            StreamWriter sw = new StreamWriter(file);
            xs.Serialize(sw, this);
            sw.Close();
        }
        #endregion
    }

}
